<?php

class re_form_element extends re_dom_input
{
	protected $validationRules;
	
	public function __construct($attributeName=null)
	{
		parent::__construct();
		
		$this->attributes['name'] = $attributeName;
		$this->attributes['type'] = $this->formElementType;
	}
	
	public function setValue($value)
	{
		$this->value = $value;
		return $this;
	}
	
	public function getValue()
	{
		return $this->value;
	}
	
	public function validate($value=null)
	{
		if(!empty($this->validationRules))
		{
			foreach($this->validationRules as $rule=>$arguments)
			{
				$validation = new re_input_validation($rule);
				if($validation->check($value)==false)
				{
					return false;
				}
			}
		}
		
		return true;
	}
	
	public function addValidation($rule, $arguments=null)
	{
		$this->validationRules[$rule] = $arguments;
		return $this;
	}
	
	public function removeValidation($rule)
	{
		unset($this->validationRules[$rule]);
		return $this;
	}
	
	public function clearValidation()
	{
		$this->validationRules = array();
		return $this;
	}
	
}

?>